//
//  PieMarker.swift
//  HuaYun
//
//  Created by enghou on 2018/12/12.
//  Copyright © 2018 xyxorigation. All rights reserved.
//

import UIKit
import Charts
class PieMarker: BarMarker {
    
    override init(color: UIColor, font: UIFont, textColor: UIColor, insets: UIEdgeInsets) {
        super.init(color: color, font: font, textColor: textColor, insets: insets)
        NotificationCenter.default.addObserver(self, selector: #selector(handlenot(not:)), name: NSNotification.Name("ValueChange"), object: nil)
    }
    
    var currentidx = 0
    
    @objc func handlenot(not: Notification)->Void{
        if let obj = not.object as? Int {
            currentidx = obj
        }
    }
    
//    open override func draw(context: CGContext, point: CGPoint)
//    {
//        guard let label = self.label else { return }
//
//        let offset = self.offsetForDrawing(atPoint: point)
//
//        var rect = CGRect(
//            origin: CGPoint(
//                x: point.x + offset.x,
//                y: point.y + offset.y),
//            size: size)
//
//        rect.origin.x -= size.width / 2.0
//
//        context.saveGState()
//
//        context.setFillColor(color.cgColor)
//
//        let path = CGMutablePath.init()
//
//        path.addRoundedRect(in: rect, cornerWidth: 2, cornerHeight: 2)
//
//        context.addPath(path)
//
//        context.fillPath()
//
//        UIGraphicsPushContext(context)
//
//        label.draw(in: CGRect(x: rect.origin.x + insets.left, y: rect.origin.y + insets.top, width: _labelSize.width, height: _labelSize.height), withAttributes: _drawAttributes)
//
//        UIGraphicsPopContext()
//
//        context.restoreGState()
//    }
    
    open override func refreshContent(entry: ChartDataEntry, highlight: Highlight)
    {
        
        if let entry = entry as? PieChartDataEntry {
            if currentidx == 0 {
                self.label = (entry.label ?? "") + ":" + String(Int(entry.y)) + "人"
            } else {
                self.label = (entry.label ?? "") + ":" + String(Int(entry.y) / 1000000) + "万元"
            }
        }
    }
}
